<template>
  <view class="dark header-container">
    <view class="icon-search-box"> <i class="iconfont icon-search"></i></view>
    <view class="title header-title">
      <view
        class="text recommend"
        :class="{ active: isActive(indexPage) }"
        @click="switchTab(indexPage)"
      >
        推荐
      </view>
      <view
        class="text localCity"
        :class="{ active: isActive(cityPage) }"
        @click="switchTab(cityPage)"
      >
        同城
      </view>
    </view>
    <view class="right-view"></view>
  </view>
</template>

<script>
  import { cityPage, indexPage } from "@/API/pageConst";

  export default {
    name: "IndexHeader",
    components: {},
    data() {
      return {
        narginTop: 0,
        indexPage,
        cityPage,
      };
    },
    methods: {
      switchTab(path) {
        uni.switchTab({
          url: path,
        });
      },
      isActive(path) {
        const pages = getCurrentPages();
        const currentPage = pages[pages.length - 1];
        return currentPage.route === path;
      },
    },
  };
</script>

<style>
  .right-view {
    width: 40px;
  }
  .icon-search-box {
    /* position: absolute; */
    top: 0;
    left: 2px;
    color: #ffffff;
    width: 40px;
    text-align: center;
    font-size: 20px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .title {
    text-align: center;
    color: #808080;
  }
  .text {
    display: inline;
    color: #808080;
    margin: 0 10px;
  }
  .active {
    color: #ffffff;
  }
</style>
